#!/bin/bash

# Copyright (c) KylinSoft Co., Ltd. 2016-2024.All rights reserved.
## kylin-kmre-make-image is licensed under the Apache License, Version 2.0.
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##         http://www.apache.org/licenses/LICENSE-2.0
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

for name in $@; do
	#mkdir -p /var/lib/kmre/${name}/acct/
	#mkdir -p /var/lib/kmre/${name}/cache/
	#mkdir -p /var/lib/kmre/${name}/config/
	#mkdir -p /var/lib/kmre/${name}/data/
	mkdir -p /var/lib/kmre/${name}/mnt/
	chmod 0755 /var/lib/kmre/${name}/mnt/
	chown 0.1000 /var/lib/kmre/${name}/mnt/
	#mkdir -p /var/lib/kmre/${name}/storage/
	mkdir -p /var/lib/kmre/${name}/sockets/

	chmod a+rwx /var/lib/kmre/${name}/sockets/

	docker create \
		--name ${name} \
		--device=/dev/dri:/dev/dri/:rwm \
		--device=/dev/input:/dev/input/:rwm \
		--device=/dev/binder:/dev/binder:rwm \
		--device=/dev/hwbinder:/dev/hwbinder:rwm \
		--device=/dev/vndbinder:/dev/vndbinder:rwm \
		--device=/dev/ashmem:/dev/ashmem:rwm \
		--device=/dev/fuse:/dev/fuse:rwm \
		--device=/dev/ion:/dev/ion:rwm \
		--device=/dev/kmsg:/dev/kmsg:rwm \
                --cap-add ALL \
                --security-opt apparmor=unconfined \
                --security-opt seccomp=unconfined \
                -v /var/lib/kmre/${name}/acct/:/acct/:rw \
                -v /var/lib/kmre/${name}/cache/:/cache/:rw \
                -v /var/lib/kmre/${name}/config/:/config/:rw \
                -v /var/lib/kmre/${name}/data/:/data/:rw \
                -v /var/lib/kmre/${name}/mnt/:/mnt/:rw \
                -v /var/lib/kmre/${name}/storage/:/storage/:rw \
                -v /var/lib/kmre/${name}/sockets/:/sockets/:rw \
                -v /tmp/android/:/kmre/:rw \
		--tty=true \
		--dns=114.114.114.114 \
		kmre2:v2.0-200317.16 /init.kmre
done

